<?php

namespace App\Console\Commands;

use App\Customer;
use App\ProjectUser;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;

class Dongguan extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'dongguan';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '将东莞的客户拉近黄金小镇';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $userProject = ProjectUser::where('project_id', 16)->chunkById(10,function ($userProjects){

            foreach ($userProjects as $userProject){
                $customers = Customer::whereIsSea(1)
                    ->where(function ($query){
                        $query ->where('detail_address', 'like', '%东莞%')
                            ->orWhere('detail_address','like','%深圳%');

                    })
                    ->orderBy('sea_time','asc')
                   ->take(20)->get();
                foreach ($customers as $customer) {
                    Log::channel('sea')->info('转移前'.$customer->customer_id,[$customer->owner_user_id]);
                    /**
                     * @var Customer $customer
                     */
                    $customer->owner_user_id = $userProject->user_id;
                    $customer->project_id=16;
                    $customer->update_time = time();
                    $customer->deal_time = time();
                    $customer->create_time = time();
                    $customer->is_sea=0;
                    $customer->follow = '待跟进';
                    $customer->status = '潜在客户';
                    $customer->ro_user_id = '';
                    $customer->rw_user_id = '';
                    $customer->save();
                    $this->info($customer->customer_id);
                    Log::channel('sea')->info('转移后'.$customer->customer_id,[$customer->owner_user_id]);
            }
        }



        });


    }
}
